home *** CD-ROM | disk | FTP | other *** search
- ##===========================================================================
- ## URL construction utilities.
- ##===========================================================================
-
- #############################################################################
- #############################################################################
- ## ##
- ## Mostly by convention, the DynaWeb URL looks something like: ##
- ## ##
- ## http://www.ebt.com/<service>/<path>;<url_params>?<query_params> ##
- ## ##
- ## where <service> is usually "dynaweb" and where <path> consists of: ##
- ## ##
- ## <root_path>/@<script_name>/<selection> ##
- ## ##
- ## and where <root_path> consists of: ##
- ## ##
- ## <collection_name>/<collection_name>/.../<book_name> ##
- ## ##
- ## Note that <script> may refer to either a dwScript or a dwTemplate, ##
- ## and <selection> semantics are script-dependent. ##
- ## ##
- ## Example: ##
- ## ##
- ## http://www.ebt.com/dynaweb/Manuals/Admin_guide/@BookTocView/446 ##
- ## | | | | | ##
- ## Service-------+ | | | | ##
- ## Collection---+ | | | ##
- ## Book--------+ | | ##
- ## Viewing template--+ | ##
- ## Target node--+ ##
- ## ##
- #############################################################################
- #############################################################################
-
- ##==============================================================================
- ## Build URL fragments that are suitable for constructing
- ## different kinds of URLs. The following parts are made:
- ##
- ## BaseUrl - A fully qualified URL including the root path
- ## (note: ends with a '/'). Suitable for use as a <BASE> HREF.
- ## Example: http://www.foo.com/dynaweb/collection/book/
- ##
- ## BasePath - Like the BaseUrl, but does not include the
- ## scheme, host, or port, and does not end with '/'.
- ## Suitable for use as a relative Url.
- ## Example: /dynaweb/collection/book
- ##
- ## RootAbsUrlPath - Like BasePath, but does not include the
- ## URL prefix or service.
- ## Example: /collection/book
- ##
- ## UrlQueryString - If a query is active this will be a string
- ## representing the query preceded by a '?' that is
- ## suitable for tacking on the end of URLs
- ## Example: ?DwebQuery=this+is+a+search+string
- ##
- ## UrlParamString - This is a string that is suitable for
- ## inserting in the URL between the path and the
- ## query string. It contains state variables for
- ## the current "session".
- ## Example: ;td=3;hf=1
- ##
- ## Careful: If RootPath is empty, avoid sending back a trailing slash.
- ##=============================================================================
-
- dwScript dwMakeUrlParts {
- set root [dwGetRootPath]
- set service [dwGetUrlNthPathSeg 0]
- set prefix [dwGetUrlPrefix]
- set script [dwGetUrlNthPathSeg [expr [dwGetUrlNumPathSegs] - 1]]
-
- if {$prefix == "/"} {set prefix ""}
-
- ## Build BasePath, RootAbsUrlPath, and BaseUrl
-
- dwSet BasePath $prefix/$service
- dwSet Service $service
-
- if {$root == ""} {
- dwSet RootAbsUrlPath $prefix/$service
- } else {
- dwSet RootAbsUrlPath $prefix/$service/$root
- }
-
- set port [dwGetUrlPort]
- if {$port == "80"} {
- dwSet dwPort :$port
- } else {
- set dwPort ""
- }
-
- dwSet BaseUrl \
- "[dwGetUrlScheme]://[dwGetUrlServer]:[dwGetUrlPort]$RootAbsUrlPath/"
-
- ##=======================================================================
- ## Build a URL-encoded version of the the query parameter
- ## so we can tack it on URLs we create.
- ## [TODO: built-in function "dwGetEncodedUrlQueryParam"]
- ##=======================================================================
-
- if {[dwGet ActiveQuery] != ""} {
- dwSet UrlQueryString "?DwebQuery=[dwUrlEncode [dwGetUrlQueryParam DwebQuery]]"
- } else {
- dwSet UrlQueryString ""
- }
-
- ##=======================================================================
- ## Turn the current state into a semicolon-separated list of
- ## key=value parameters.
- ##=======================================================================
-
- dwSet UrlParamString ""
- if {[dwGet State__CollTocDepth] != [dwGetParam Default__CollTocDepth]} {
- dwSet UrlParamString \
- "$UrlParamString;cd=[dwUrlEncode [dwGet State__CollTocDepth]]"
- }
- if {[dwGet State__TocDepth] != [dwGetParam Default__TocDepth]} {
- dwSet UrlParamString \
- "$UrlParamString;td=[dwUrlEncode [dwGet State__TocDepth]]"
- }
- if {[dwGet State__Frames] != [dwGet State__FramesSupport]} {
- dwSet UrlParamString \
- "$UrlParamString;hf=[dwUrlEncode [dwGet State__Frames]]"
- }
- if {[dwGet State__Tables] != [dwGetParam Default__TablesFlag]} {
- dwSet UrlParamString \
- "$UrlParamString;ht=[dwUrlEncode [dwGet State__Tables]]"
- }
- if {[dwGet State__Entities] != [dwGetParam Default__EntitiesFlag]} {
- dwSet UrlParamString \
- "$UrlParamString;he=[dwUrlEncode [dwGet State__Entities]]"
- }
- if {[dwGet State__NoNavigation] != 0} {
- dwSet UrlParamString "$UrlParamString;nn=1"
- }
- if {[dwGet ActiveQuery] != ""} {
- if {[dwGet State__NoAutoHit] != 0} {
- dwSet UrlParamString "$UrlParamString;nh=1"
- }
- }
-
- set cs_state [dwGet State__ContentStyle]
- if {$cs_state != "" && $cs_state != "default"} {
- dwSet UrlParamString \
- "$UrlParamString;cs=[dwUrlEncode $cs_state]"
- }
- set ts_state [dwGet State__TocStyle]
- if {$ts_state != "" && $ts_state != "default"} {
- dwSet UrlParamString \
- "$UrlParamString;ts=[dwUrlEncode $ts_state]"
- }
-
-
- ## Suppress the return value, else it goes to the client and
- ## messes up the output stream.
-
- dwReturn
- }
-
-
- ## Here's an example of how to remove a URL param from the URL.
-
- dwScript RemoveHfUrlParam {
- regsub {;hf=[0-9]+} "[dwGet UrlParamString]" {} UrlParamString
- dwReturn
- }
-